<<<<<<< HEAD
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultResponse;
import com.wyz.common.ResultVo;
import com.wyz.entity.CourseEntity;
import com.wyz.entity.CourseTableEntity;
import com.wyz.service.CourseService;
import com.wyz.service.CourseTableService;
import com.wyz.vo.CourseTableVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/12/25 14:44
 */
@RestController
@Slf4j
@RequestMapping("/courseTable")
public class CourseTableController {
    @Resource
    private CourseTableService courseTableService;
    @Resource
    private CourseService courseService;

    //老师查询所有选课信息
    @AutoLog("老师查询所有课程信息")
    @GetMapping("/queryCourseTableByPage")
    public ResultVo<List<CourseTableVO>> queryCourseTableByPage(){
        log.info("查询选课信息请求");
        List<CourseTableVO> courseTableVOS = courseTableService.queryAllCourseTable();
        log.info("查询选课信息响应,参数:{}", courseTableVOS);
        return new ResultVo<>(200,"ok",courseTableVOS);
    }
    //学生查看自己的选课信息
    @AutoLog("学生查询所有课程信息")
    @GetMapping("/queryCourseTableByStudentId/{studentId}")
    public ResultVo<List<CourseTableVO>> queryCourseTableByStudentId(@PathVariable("studentId") Integer studentId){
        log.info("学生查询选课信息请求,参数:{}", studentId);
        List<CourseTableVO> courseTableVOS = courseTableService.queryCourseTableByStudentId(studentId);
        log.info("学生查询选课信息响应,参数:{}", courseTableVOS);
        return new ResultVo<>(200,"ok",courseTableVOS);
    }

    //退课
    @AutoLog("退课")
    @GetMapping("/deleteCourseTable/{coursetableId}")
    public ResultVo<Boolean> deleteCourseTable(@PathVariable("coursetableId") Integer coursetableId){
        log.info("退课请求,参数:{}", coursetableId);
        try {
            boolean b = courseTableService.deleteCourseTable(coursetableId);
            log.info("退课响应,参数:{}", b);
            return new ResultVo<>(200,"ok",b);
        }catch (Exception e) {
            return new ResultVo<>(500,"fail",false);
        }
    }
    //分页查询课程信息
    @AutoLog("分页查询课程信息")
    @GetMapping("/queryCourseByPage/{page}")
    public ResultVo<Map<String, Object>> queryCourseByPage(@PathVariable("page") int page) {
        log.info("分页查询课程信息请求,参数:{}", page);
        IPage<CourseEntity> courseListPage = courseService.getCourseListByPage(page);
        List<CourseEntity> courseList = courseListPage.getRecords();//获取分页查询结果
        int total = (int)courseListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("courseList",courseList);
        resultMap.put("pageList",pageList);

        log.info("获取分页课程列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }


    //添加选课信息
    @AutoLog("添加选课信息")
    @PostMapping("/addCourseTable")
    public ResultVo<Boolean> addCourseTable(@RequestBody CourseTableEntity courseTableEntity){
        log.info("选课请求,参数:{}", courseTableEntity);
        try {
            if (courseTableService.addCourseTable(courseTableEntity)){
                log.info("添加学生信息成功:{}",courseTableEntity);
                return new ResultVo<>(200,"ok",true);
            }
            return new ResultVo<>(500,"fail",false);
        } catch (Exception e) {
            return new ResultVo<>(500,"fail",false);
        }
    }
}
=======
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultResponse;
import com.wyz.common.ResultVo;
import com.wyz.entity.CourseEntity;
import com.wyz.entity.CourseTableEntity;
import com.wyz.service.CourseService;
import com.wyz.service.CourseTableService;
import com.wyz.vo.CourseTableVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/12/25 14:44
 */
@RestController
@Slf4j
@RequestMapping("/courseTable")
public class CourseTableController {
    @Resource
    private CourseTableService courseTableService;
    @Resource
    private CourseService courseService;

    //老师查询所有选课信息
    @AutoLog("老师查询所有课程信息")
    @GetMapping("/queryCourseTableByPage")
    public ResultVo<List<CourseTableVO>> queryCourseTableByPage(){
        log.info("查询选课信息请求");
        List<CourseTableVO> courseTableVOS = courseTableService.queryAllCourseTable();
        log.info("查询选课信息响应,参数:{}", courseTableVOS);
        return new ResultVo<>(200,"ok",courseTableVOS);
    }
    //学生查看自己的选课信息
    @AutoLog("学生查询所有课程信息")
    @GetMapping("/queryCourseTableByStudentId/{studentId}")
    public ResultVo<List<CourseTableVO>> queryCourseTableByStudentId(@PathVariable("studentId") Integer studentId){
        log.info("学生查询选课信息请求,参数:{}", studentId);
        List<CourseTableVO> courseTableVOS = courseTableService.queryCourseTableByStudentId(studentId);
        log.info("学生查询选课信息响应,参数:{}", courseTableVOS);
        return new ResultVo<>(200,"ok",courseTableVOS);
    }

    //退课
    @AutoLog("退课")
    @GetMapping("/deleteCourseTable/{coursetableId}")
    public ResultVo<Boolean> deleteCourseTable(@PathVariable("coursetableId") Integer coursetableId){
        log.info("退课请求,参数:{}", coursetableId);
        try {
            boolean b = courseTableService.deleteCourseTable(coursetableId);
            log.info("退课响应,参数:{}", b);
            return new ResultVo<>(200,"ok",b);
        }catch (Exception e) {
            return new ResultVo<>(500,"fail",false);
        }
    }
    //分页查询课程信息
    @AutoLog("分页查询课程信息")
    @GetMapping("/queryCourseByPage/{page}")
    public ResultVo<Map<String, Object>> queryCourseByPage(@PathVariable("page") int page) {
        log.info("分页查询课程信息请求,参数:{}", page);
        IPage<CourseEntity> courseListPage = courseService.getCourseListByPage(page);
        List<CourseEntity> courseList = courseListPage.getRecords();//获取分页查询结果
        int total = (int)courseListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("courseList",courseList);
        resultMap.put("pageList",pageList);

        log.info("获取分页课程列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }


    //添加选课信息
    @AutoLog("添加选课信息")
    @PostMapping("/addCourseTable")
    public ResultVo<Boolean> addCourseTable(@RequestBody CourseTableEntity courseTableEntity){
        log.info("选课请求,参数:{}", courseTableEntity);
        try {
            if (courseTableService.addCourseTable(courseTableEntity)){
                log.info("添加学生信息成功:{}",courseTableEntity);
                return new ResultVo<>(200,"ok",true);
            }
            return new ResultVo<>(500,"fail",false);
        } catch (Exception e) {
            return new ResultVo<>(500,"fail",false);
        }
    }
}
>>>>>>> be516e15a35375b38cf973b1ce88c92dd1ceba03
